package com.yanqu.road.server.cmd.strongholdwar;

import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.activity.StrongholdWarCrossProto;
import com.yanqu.road.pb.activity.StrongholdWarProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.strongholdwar.StrongholdWarMgr;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;

import java.util.List;
import java.util.Set;

@Cmd(code = CrossProtocol.C_CROSS_STRONGHOLD_TRADE_DETAIL,desc = "")
public class CrossStrongholdTradeDetailCmd extends CrossUnionCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        StrongholdWarCrossProto.CrossStrongholdTradeDetailReqMsg reqMsg = StrongholdWarCrossProto.CrossStrongholdTradeDetailReqMsg.parseFrom(packet.getBytes());
        int activityId = reqMsg.getActivityId();
        List<Long> memberIdList = reqMsg.getMemberIdList();
        Set<Long> userSet = StrongholdWarMgr.getUnTradeUserList(activityId, memberIdList);
        StrongholdWarProto.StrongholdTradeDetailRespMsg.Builder resp = StrongholdWarProto.StrongholdTradeDetailRespMsg.newBuilder();
            for (Long userId : userSet) {
                StrongholdWarProto.StrongholdTradeMemberDataMsg.Builder msg = StrongholdWarProto.StrongholdTradeMemberDataMsg.newBuilder();
                    msg.setPlayerBaseData(PlayerBasePb.parsePlayerBaseTempMsg(CrossUserMgr.getUserBaseInfo(userId)));
                msg.setUserId(userId);
                resp.addMemberData(msg);
            }
        YanQuMessage message = YanQuMessageUtils.buildMessage(ClientProtocol.U_STRONGHOLD_TRADE_DETAIL, resp);
        MessageHelper.sendPacket(serverId, packet.getPlayerId(), message);
    }

    @Override
    public void sendData() {

    }
}
